package com.spddr.pmos.jpa;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Embeddable;

import org.joda.time.LocalDate;
import org.joda.time.Period;

@Embeddable
public class ContractDetailId implements java.io.Serializable {
	private static final long serialVersionUID = 1L;

	private long contract;
	private LocalDate date;
	private Period period;
	private int psv;

	public ContractDetailId() {
	}

	public ContractDetailId(long contract, LocalDate date, Period period, int psv) {
		this.contract = contract;
		this.date = date;
		this.period = period;
		this.psv = psv;
	}

	@Column(name = "contract", nullable = false)
	public long getContract() {
		return this.contract;
	}

	public void setContract(long contract) {
		this.contract = contract;
	}

	@Column(name = "date", nullable = false, length = 10)
	@Convert(converter = cn.seqdata.jpa.converter.LocalDateConverter.class)
	public LocalDate getLocalDate() {
		return this.date;
	}

	public void setLocalDate(LocalDate date) {
		this.date = date;
	}

	@Column(name = "period", nullable = false, length = 8)
	@Convert(converter = cn.seqdata.jpa.converter.PeriodConverter.class)
	public Period getPeriod() {
		return this.period;
	}

	public void setPeriod(Period period) {
		this.period = period;
	}

	@Column(name = "psv", nullable = false)
	public int getPsv() {
		return this.psv;
	}

	public void setPsv(int psv) {
		this.psv = psv;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (contract ^ (contract >>> 32));
		result = prime * result + ((date == null) ? 0 : date.hashCode());
		result = prime * result + ((period == null) ? 0 : period.hashCode());
		result = prime * result + psv;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ContractDetailId other = (ContractDetailId) obj;
		if (contract != other.contract)
			return false;
		if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		if (period == null) {
			if (other.period != null)
				return false;
		} else if (!period.equals(other.period))
			return false;
		if (psv != other.psv)
			return false;
		return true;
	}
}